package com.netx.generics.basic;
import java.util.Map;
import java.util.HashMap;


public class ContextRules {

	private boolean _allowOtherProperties;
	private final Map<String,PropertyDefinition> _defs;
	
	public ContextRules(boolean allowOtherProperties) {
		_defs = new HashMap<String,PropertyDefinition>();
		_allowOtherProperties = allowOtherProperties;
	}

	public boolean getAllowOtherProperties() {
		return _allowOtherProperties;
	}
	
	public void setAllowOtherProperties(boolean allowOtherProperties) {
		_allowOtherProperties = allowOtherProperties;
	}
	
	public boolean add(PropertyDefinition def) {
		Checker.checkNull(def, "def");
		return _defs.put(def.getPropertyName(), def) != null;
	}
	
	// For Context:
	PropertyDefinition getDefinitionFor(String name) {
		return _defs.get(name);
	}

	// For RootContext:
	PropertyDefinition removeDefinitionFor(String name) {
		return _defs.remove(name);
	}

	// For Context:
	Map<String,PropertyDefinition> getDefinitions() {
		return _defs;
	}
}
